package com.sugar.subscribe.course.module.business.dal.mysql.withdrawrecord;

import com.sugar.subscribe.course.framework.common.pojo.PageParam;
import com.sugar.subscribe.course.framework.common.pojo.PageResult;
import com.sugar.subscribe.course.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.sugar.subscribe.course.framework.mybatis.core.mapper.BaseMapperX;
import com.sugar.subscribe.course.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.sugar.subscribe.course.module.business.controller.app.withdrawrecord.vo.AppWithdrawRecordRespVO;
import com.sugar.subscribe.course.module.business.dal.dataobject.coach.CoachDO;
import com.sugar.subscribe.course.module.business.dal.dataobject.withdrawrecord.WithdrawRecordDO;
import org.apache.ibatis.annotations.Mapper;
import com.sugar.subscribe.course.module.business.controller.admin.withdrawrecord.vo.*;

/**
 * 提现记录 Mapper
 *
 * @author Ysugar
 */
@Mapper
public interface WithdrawRecordMapper extends BaseMapperX<WithdrawRecordDO> {

    default PageResult<WithdrawRecordRespVO> selectPage(WithdrawRecordPageReqVO reqVO) {
        return selectJoinPage(reqVO, WithdrawRecordRespVO.class, new MPJLambdaWrapperX<WithdrawRecordDO>()
                .selectAll(WithdrawRecordDO.class)
                .selectAs(CoachDO::getName, WithdrawRecordRespVO::getCoachName)
                .selectAs(CoachDO::getMobile, WithdrawRecordRespVO::getCoachMobile)
                .leftJoin(CoachDO.class, CoachDO::getId, WithdrawRecordDO::getCoachId)
                .eqIfPresent(WithdrawRecordDO::getCoachId, reqVO.getCoachId())
                .eqIfPresent(WithdrawRecordDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(WithdrawRecordDO::getDoneTime, reqVO.getDoneTime())
                .betweenIfPresent(WithdrawRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(WithdrawRecordDO::getId));
    }

    default PageResult<AppWithdrawRecordRespVO> appGetWithdrawRecordPage(PageParam pageParam, Long coachId){
        return selectJoinPage(pageParam, AppWithdrawRecordRespVO.class, new MPJLambdaWrapperX<WithdrawRecordDO>()
                .selectAs(WithdrawRecordDO::getId, AppWithdrawRecordRespVO::getId)
                .selectAs(WithdrawRecordDO::getAmount, AppWithdrawRecordRespVO::getAmount)
                .selectAs(WithdrawRecordDO::getStatus, AppWithdrawRecordRespVO::getStatus)
                .selectAs(WithdrawRecordDO::getFailCause, AppWithdrawRecordRespVO::getFailCause)
                .selectAs(WithdrawRecordDO::getDoneTime, AppWithdrawRecordRespVO::getDoneTime)
                .selectAs(WithdrawRecordDO::getCreateTime, AppWithdrawRecordRespVO::getCreateTime)
                .eqIfPresent(WithdrawRecordDO::getCoachId, coachId));
    }
}